package org.refresh.injectors.xml;

import java.util.List;
import java.util.Map;

import org.refresh.injectors.TemplateInjector;

/******************************************************************************
 * Copyright (c) 2005, 2006 Jules White.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Jules White - initial API and implementation 
 ****************************************************************************/
public class ForEachAnnotation extends AbstractAnnotation {

	public static final String TYPE = "for-each";
	
	public static final String LIST_OPTION = "list";
	
	public ForEachAnnotation(){
		super(TYPE);
		addRequiredOption("list");
	}
	
	@Override
	protected String handleImpl(String template, Map options, Map bindings) {
		String listname = (String)options.get(LIST_OPTION);
		List list = (List)bindings.get(listname);
		String result = "";
		
		TemplateInjector injector = getTemplateInjector();
		for(Object o : list){
			result += injector.inject(template, o);
		}
		
		return result;
	}

}
